package com.nhancv.kurentoandroid.main;

import android.Manifest;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;

import com.hannesdorfmann.mosby.mvp.MvpActivity;
import com.karumi.dexter.Dexter;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import com.nhancv.kurentoandroid.R;
import com.nhancv.kurentoandroid.broadcaster.BroadCasterActivity_;
import com.nhancv.kurentoandroid.one2one.One2OneActivity_;
import com.nhancv.kurentoandroid.viewer.ViewerActivity_;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;

import java.util.List;


/**
 * Created by nhancao on 9/18/16.
 */

@EActivity(R.layout.activity_main)
public class MainActivity extends MvpActivity<MainView, MainPresenter> implements MainView {
    private static final String TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        permission();
    }


    private void permission() {
        Dexter.withActivity(MainActivity.this)
          .withPermissions(
            Manifest.permission.CALL_PHONE,
            Manifest.permission.CAMERA,
            Manifest.permission.ANSWER_PHONE_CALLS,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.RECORD_AUDIO
          )
          .withListener(new MultiplePermissionsListener() {
              @Override
              public void onPermissionsChecked(MultiplePermissionsReport report) {
                  Log.d("checkpermission", String.valueOf(report.areAllPermissionsGranted()));

                  if (report.areAllPermissionsGranted()) {
                      Log.d("checkpermission", "granted");
                  } else if (report.isAnyPermissionPermanentlyDenied()) {
                      Log.d("checkpermission", "not granted");
                  }
              }

              @Override
              public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
              }
          }).onSameThread().check();


    }


    @Click(R.id.btBroadCaster)
    protected void btBroadCasterClick() {
        BroadCasterActivity_.intent(this).start();
    }

    @Click(R.id.btViewer)
    protected void btViewerClick() {
        ViewerActivity_.intent(this).start();
    }

    @Click(R.id.btOne2One)
    protected void btOne2OneClick() {
        One2OneActivity_.intent(this).start();
    }

    @NonNull
    @Override
    public MainPresenter createPresenter() {
        return new MainPresenter(getApplication());
    }

}
